import Day from 'dayjs'

export function debounce(fn, time = 500) {
  let timer = null;
  return (...arg) => {
    if (timer) {
      clearTimeout(timer);
    }
    timer = setTimeout(() => {
      fn(...arg);
    }, time);
  };
}

export function throttle(fn, time = 500) {
  let pre = Date.now();
  return (...arg) => {
    let distance = Date.now() - pre;
    if (distance > time) {
      fn(...arg);
    }
  };
}


export function foramtTime (time,fmt = "YYYY-MM-DD") {
  return Day(time).format(fmt);
}

export function dotWang (num) {
  if(num > 10000) {
    return (num/10000).toFixed(1) + '万';
  }
  return num;
}